/*
 * VHJsSimpleData.java
 * Created on 20 juin 2009
 *
 * VirtualHockey Internet Platform
 * http://code.google.com/p/virtualhockey/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */

package com.hockeo.vhweb.client.utils;

import com.google.gwt.user.client.ui.AbstractImagePrototype;

/**
 * Simple data object which is targeted at non-remote client side objects that need to be
 * rendered with a name and optionally an icon.
 *
 * @version $Id$
 * @author janjanke
 */
public class VHJsSimpleData extends VHJsData
{
  public static final String PARAM_LABEL      = "label";
  public static final String PARAM_ICON       = "$icon$";
  public static final String PARAM_CHILD_TYPE = "$childType$";
  public static final String PARAM_PARENT_ID  = "$parentId$";

  public enum ChildType
  {
    /** Indicates that this item has no children. */
    NONE,

    /** Indicates that this item has client side defined children. */
    CLIENT,

    /** Indicates that this item has children that must be loaded from the server. */
    REMOTE;
  }

  public VHJsSimpleData( String strId )
  {
    this( strId, null, null );
  }

  public VHJsSimpleData( String strId, String strLabel )
  {
    this( strId, strLabel, null );
  }

  public VHJsSimpleData( String strId, String strLabel, AbstractImagePrototype icon )
  {
    set( PARAM_ID, strId );

    if ( strLabel != null )
      set( PARAM_LABEL, strLabel );

    if ( icon != null )
      set( PARAM_ICON, icon );
  }

  /**
   * Sets the child type of this object. Please see the enumeration {@link ChildType} for
   * details.
   *
   * @param type
   */
  public void setChildType( ChildType type )
  {
    set( PARAM_CHILD_TYPE, type.name() );
  }

  public ChildType getChildType()
  {
    String str = getString( PARAM_CHILD_TYPE );

    if ( str == null )
      return ChildType.NONE;

    return ChildType.valueOf( str );
  }

  public void setParentId( String str )
  {
    set( PARAM_PARENT_ID, str );
  }

  public String getParentId()
  {
    return getString( PARAM_PARENT_ID );
  }

  @Override
  public String getType()
  {
    return "SimpleData";
  }

  @Override
  public boolean isRemote()
  {
    return false;
  }

  public String getLabel()
  {
    return getString( PARAM_LABEL );
  }

  public AbstractImagePrototype getIcon()
  {
    return (AbstractImagePrototype) get( PARAM_ICON );
  }

  @Override
  public String toString()
  {
    return getLabel();
  }
}
